﻿using System.Xml.Linq;
using BattleFury.Lib.Extensions;
using Microsoft.Xna.Framework;

namespace BattleFury.Lib.Controls
{
	public class TextBlock
		: Control
	{
		public string Text { get; set; }
		public Color ForegroundColor { get; set; }

		public override void Deserialize(XElement element, object callingObject)
		{
			base.Deserialize(element, callingObject);

			Text = element.GetString("Text");
			ForegroundColor = element.GetColor("ForegroundColor", Color.Black);
		}

		public override void Update(GameTime gameTime)
		{

		}

		public override void Draw(GameTime gameTime)
		{
			var textSize = Font.MeasureString(Text);
			var textPosition = new Vector2(Position.X, Position.Y + ((Size.Y / 2) - (textSize.Y / 2)));
			SpriteBatch.DrawString(Font, Text, textPosition + Vector2.One, Color.Black.WithOpacity(0.5f));
			SpriteBatch.DrawString(Font, Text, textPosition, ForegroundColor);
		}
	}
}